home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu017.dms / pu017.adf / Gadgets / Example7.c < prev    next >
C/C++ Source or Header  |  1990-01-30  |  9KB  |  258 lines

  1. /* Example7                                                           */
  2. /* This program will open a normal window which is connected to the   */
  3. /* Workbench Screen. The window will use all System Gadgets, and will */
  4. /* close first when the user has selected the System gadget Close     */
  5. /* window. Inside the window we have put a String gadget.             */
  6.  
  7.  
  8.  
  9. #include <intuition/intuition.h>
  10.  
  11.  
  12.  
  13. struct IntuitionBase *IntuitionBase;
  14.  
  15.  
  16.  
  17. /* THE STRING GADGET's STRUCTURES: */
  18.  
  19. /* The coordinates for the box: */
  20. SHORT my_points[]=
  21. {
  22.    -7, -4, /* Start at position (-7, -4) */
  23.   200, -4, /* Draw a line to the right to position (200,-4) */
  24.   200, 11, /* Draw a line down to position (200,11) */
  25.    -7, 11, /* Draw a line to the right to position (-7,11) */
  26.    -7, -4  /* Finish of by drawing a line up to position (-7,-4) */ 
  27. };
  28.  
  29. /* The Border structure: */
  30. struct Border my_border=
  31. {
  32.   0, 0,        /* LeftEdge, TopEdge. */
  33.   1,           /* FrontPen, colour register 1. */
  34.   0,           /* BackPen, for the moment unused. */
  35.   JAM1,        /* DrawMode, draw the lines with colour 1. */
  36.   5,           /* Count, 5 pair of coordinates in the array. */
  37.   my_points,   /* XY, pointer to the array with the coordinates. */
  38.   NULL,        /* NextBorder, no other Border structures are connected. */
  39. };
  40.  
  41.  
  42.  
  43. /* The IntuiText structure: */
  44. struct IntuiText my_text=
  45. {
  46.   1,         /* FrontPen, colour register 1. */
  47.   0,         /* BackPen, colour register 0. */
  48.   JAM1,      /* DrawMode, draw the characters with colour 1, do not */
  49.              /* change the background. */ 
  50.   -53, 0,    /* LeftEdge, TopEdge. */
  51.   NULL,      /* ITextFont, use default font. */
  52.   "Text:",   /* IText, the text that will be printed. */
  53.   NULL,      /* NextText, no other IntuiText structures. */
  54. };
  55.  
  56.  
  57.  
  58. UBYTE my_buffer[50]; /* 50 characters including the NULL-sign. */
  59. UBYTE my_undo_buffer[50]; /* Must be at least as big as my_buffer. */
  60.  
  61.  
  62.  
  63. struct StringInfo my_string_info=
  64. {
  65.   my_buffer,       /* Buffer, pointer to a null-terminated string. */
  66.   my_undo_buffer,  /* UndoBuffer, pointer to a null-terminated string. */
  67.                    /* (Remember my_buffer is equal to &my_buffer[0]) */
  68.   0,               /* BufferPos, initial position of the cursor. */
  69.   50,              /* MaxChars, 50 characters + null-sign ('\0'). */
  70.   0,               /* DispPos, first character in the string should be */
  71.                    /* first character in the display. */
  72.  
  73.   /* Intuition initializes and maintaines these variables: */
  74.  
  75.   0,               /* UndoPos */
  76.   0,               /* NumChars */
  77.   0,               /* DispCount */
  78.   0, 0,            /* CLeft, CTop */
  79.   NULL,            /* LayerPtr */
  80.   NULL,            /* LongInt */
  81.   NULL,            /* AltKeyMap */
  82. };
  83.  
  84.  
  85. struct Gadget my_gadget=
  86. {
  87.   NULL,          /* NextGadget, no more gadgets in the list. */
  88.   68,            /* LeftEdge, 68 pixels out. */
  89.   30,            /* TopEdge, 30 lines down. */
  90.   198,           /* Width, 198 pixels wide. */
  91.   8,             /* Height, 8 pixels lines heigh. */
  92.   GADGHCOMP,     /* Flags, draw the select box in the complement */
  93.                  /* colours. Note: it actually only the cursor which */
  94.                  /* will be drawn in the complement colours (yellow). */
  95.                  /* If you set the flag GADGHNONE the cursor will not be */
  96.                  /* highlighted, and the user will therefore not be able */
  97.                  /* to see it. */
  98.   GADGIMMEDIATE| /* Activation, our program will recieve a message when */
  99.   RELVERIFY,     /* the user has selected this gadget, and when the user */
  100.                  /* has released it. */ 
  101.   STRGADGET,     /* GadgetType, a String gadget. */
  102.   (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
  103.   NULL,          /* SelectRender, NULL since we do not supply the gadget */
  104.                  /* with an alternative image. */
  105.   &my_text,      /* GadgetText, a pointer to our IntuiText structure. */
  106.   NULL,          /* MutualExclude, no mutual exclude. */
  107.   (APTR) &my_string_info, /* SpecialInfo, a pointer to a StringInfo str. */
  108.   0,             /* GadgetID, no id. */
  109.   NULL           /* UserData, no user data connected to the gadget. */
  110. };
  111.  
  112.  
  113.  
  114. /* Declare a pointer to a Window structure: */ 
  115. struct Window *my_window;
  116.  
  117. /* Declare and initialize your NewWindow structure: */
  118. struct NewWindow my_new_window=
  119. {
  120.   50,            /* LeftEdge    x position of the window. */
  121.   25,            /* TopEdge     y positio of the window. */
  122.   320,           /* Width       320 pixels wide. */
  123.   100,           /* Height      100 lines high. */
  124.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  125.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  126.   CLOSEWINDOW|   /* IDCMPFlags  The window will give us a message if the */
  127.                  /*             user has selected the Close window gad, */
  128.   GADGETDOWN|    /*             or a gadget has been pressed on, or */
  129.   GADGETUP,      /*             a gadge has been released. */
  130.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  131.   WINDOWCLOSE|   /*             Close Gadget. */
  132.   WINDOWDRAG|    /*             Drag gadget. */
  133.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  134.   WINDOWSIZING|  /*             Sizing Gadget. */
  135.   ACTIVATE,      /*             The window should be Active when opened. */
  136.   &my_gadget,    /* FirstGadget A pointer to the String gadget. */
  137.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  138.   "String Window",/* Title       Title of the window. */
  139.   NULL,          /* Screen      Connected to the Workbench Screen. */
  140.   NULL,          /* BitMap      No Custom BitMap. */
  141.   320,           /* MinWidth    We will not allow the window to become */
  142.   50,            /* MinHeight   smaller than 320 x 50, and not bigger */
  143.   640,           /* MaxWidth    than 640 x 200. */
  144.   200,           /* MaxHeight */
  145.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  146. };
  147.  
  148.  
  149.  
  150. main()
  151. {
  152.   /* Boolean variable used for the while loop: */
  153.   BOOL close_me;
  154.  
  155.   /* Declare a variable in which we will store the IDCMP flag: */
  156.   ULONG class;
  157.  
  158.   /* Declare a pointer to an IntuiMessage structure: */
  159.   struct IntuiMessage *my_message;
  160.  
  161.  
  162.  
  163.   /* Put some text into the my_buffer string: */
  164.   strcpy( my_buffer, "Some text" );
  165.  
  166.  
  167.  
  168.   /* Before we can use Intuition we need to open the Intuition Library: */
  169.   IntuitionBase = (struct IntuitionBase *)
  170.     OpenLibrary( "intuition.library", 0 );
  171.   
  172.   if( IntuitionBase == NULL )
  173.     exit(); /* Could NOT open the Intuition Library! */
  174.  
  175.  
  176.  
  177.   /* We will now try to open the window: */
  178.   my_window = (struct Window *) OpenWindow( &my_new_window );
  179.   
  180.   /* Have we opened the window succesfully? */
  181.   if(my_window == NULL)
  182.   {
  183.     /* Could NOT open the Window! */
  184.     
  185.     /* Close the Intuition Library since we have opened it: */
  186.     CloseLibrary( IntuitionBase );
  187.  
  188.     exit();  
  189.   }
  190.  
  191.  
  192.  
  193.   /* We have opened the window, and everything seems to be OK. */
  194.  
  195.  
  196.  
  197.   close_me = FALSE;
  198.  
  199.   /* Stay in the while loop until the user has selected the Close window */
  200.   /* gadget: */
  201.   while( close_me == FALSE )
  202.   {
  203.     /* Wait until we have recieved a message: */
  204.     Wait( 1 << my_window->UserPort->mp_SigBit );
  205.  
  206.     /* Collect the message: */
  207.     my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort );
  208.  
  209.     /* Have we collected the message sucessfully? */
  210.     if(my_message)
  211.     {
  212.       /* After we have collected the message we can read it, and save any */
  213.       /* important values which we maybe want to check later: */
  214.       class = my_message->Class;      /* Save the IDCMP flag. */
  215.   
  216.       /* After we have read it we reply as fast as possible: */
  217.       /* REMEMBER! Do never try to read a message after you have replied! */
  218.       /* Some other process has maybe changed it. */
  219.       ReplyMsg( my_message );
  220.   
  221.       /* Check which IDCMP flag was sent: */
  222.       switch( class )
  223.       {
  224.         case CLOSEWINDOW:  /* The user selected the Close window gadget! */
  225.                close_me=TRUE;
  226.                break;
  227.                
  228.         case GADGETDOWN:   /* The user has selected the String gadget: */
  229.                            /* (Clicked inside the select box) */
  230.                printf("String gadget selected.\n");
  231.                break;
  232.                
  233.         case GADGETUP:     /* The user has released the String gadget: */
  234.                            /* (Pressed ENTER or RETURN) */
  235.                printf("String gadget released.\n");
  236.                break;
  237.       }
  238.     }
  239.   }
  240.  
  241.  
  242.  
  243.   /* Print out the final string: */
  244.   printf("String: %s\n", my_string_info.Buffer);
  245.  
  246.  
  247.  
  248.   /* We should always close the windows we have opened before we leave: */
  249.   CloseWindow( my_window );
  250.  
  251.  
  252.  
  253.   /* Close the Intuition Library since we have opened it: */
  254.   CloseLibrary( IntuitionBase );
  255.  
  256.   /* THE END */
  257. }
  258.